#if 0
#include "DataProcess.h"
#include "common\def.h"
#include <comLib\net.h>
#include "ImageShower.h"
#include "MsgCenter.h"


DDataProcess::DDataProcess(QObject *parent)
{
	m_iHeadSize = sizeof(HeadInfo);

	m_pMsgCenter = DMsgCenter::getInstance();
	m_videoDecoder = new CVideoDecoder();
	m_pPkt = av_packet_alloc();

	m_MsgProcess[CLIENT_MSG::UPDATE_IMAGE] = std::bind(&DDataProcess::ProcessImage, this, std::placeholders::_1, std::placeholders::_2);
	m_MsgProcess[CLIENT_MSG::MSG_IMAGE_SIZE] = std::bind(&DDataProcess::ProcessImageSize, this, std::placeholders::_1, std::placeholders::_2);
}


DDataProcess::~DDataProcess()
{
	for (auto &iter : m_RecvPacket)
	{
		delete iter.second.buffer;
	}
}

std::vector<CONNID> DDataProcess::getConnid()
{
	return m_connId;
}

EnHandleResult DDataProcess::OnPrepareListen(ITcpServer* pSender, SOCKET soListen)
{
	return EnHandleResult::HR_OK;
}

EnHandleResult DDataProcess::OnAccept(ITcpServer* pSender, CONNID dwConnID, UINT_PTR soClient)
{
	m_connId.push_back(dwConnID);
	m_RecvPacket[dwConnID] = PacketStruct();
	m_RecvPacket[dwConnID].buffer = new QByteArray();

	return EnHandleResult::HR_OK;
}

EnHandleResult DDataProcess::OnHandShake(ITcpServer* pSender, CONNID dwConnID)
{
	return EnHandleResult::HR_OK;
}

EnHandleResult DDataProcess::OnReceive(ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
	auto &recvPacket = m_RecvPacket[dwConnID];
	recvPacket.buffer->append((const char *)pData, iLength);

	do{
		if (recvPacket.bCompleteHead == false){

			memcpy(&recvPacket.headInfo, recvPacket.buffer->data(), m_iHeadSize);
			recvPacket.buffer->remove(0, m_iHeadSize);
			recvPacket.bCompleteHead = true;
		}
		if (recvPacket.bCompleteHead && recvPacket.headInfo.bodySize <= recvPacket.buffer->size()){

			run(recvPacket.headInfo, recvPacket.buffer->data());
			recvPacket.buffer->remove(0, recvPacket.headInfo.bodySize);

			recvPacket.bCompleteHead = false;
		}
	} while (recvPacket.buffer->size() >= m_iHeadSize && recvPacket.bCompleteHead == false);

	return EnHandleResult::HR_OK;
}

EnHandleResult DDataProcess::OnSend(ITcpServer* pSender, CONNID dwConnID, const BYTE* pData, int iLength)
{
	return __super::OnSend(pSender, dwConnID, pData, iLength);
}

EnHandleResult DDataProcess::OnClose(ITcpServer* pSender, CONNID dwConnID, EnSocketOperation enOperation, int iErrorCode)
{
	auto &iter = m_RecvPacket[dwConnID];
	delete iter.buffer;
	m_RecvPacket.erase(dwConnID);

	return EnHandleResult::HR_OK;
}

EnHandleResult DDataProcess::OnShutdown(ITcpServer* pSender)
{
	return __super::OnShutdown(pSender);
}

void DDataProcess::run(const HeadInfo &headInfo, const void *data)
{
	auto findRet = m_MsgProcess.find((CLIENT_MSG)headInfo.msgType);
	if (findRet != m_MsgProcess.end())
	{
		findRet->second(headInfo, data);
	}
	else
	{
		assert(false);
	}
}

bool DDataProcess::ProcessImage(const HeadInfo headInfo, const void *data)
{
	AVFrame *pFrame = nullptr;

	auto imageCb = [&](AVFrame *pFrame){
		if (pFrame)
		{
			m_pMsgCenter->handleMsg(InnerMsg::INNER_UPDATE_IMAGE, pFrame);
		}
	};
	DecoderInf::FrameCallback frameCb = std::bind(imageCb, std::placeholders::_1);


	m_pPkt->data = (uint8_t*)data;
	m_pPkt->size = headInfo.bodySize;
	m_videoDecoder->decodePkt(m_pPkt, frameCb);

	return true;
}

bool DDataProcess::ProcessImageSize(const HeadInfo, const void *data)
{
	int dataSize;

	SizeInfo sizeInfo;
	memcpy(&sizeInfo, data, sizeof(SizeInfo));

	m_pMsgCenter->handleMsg(InnerMsg::INNER_IMAGE_SIZE, &sizeInfo);

	return true;
}

DNetServer::DNetServer() :
m_pDataProcess(new DDataProcess())
{
	wchar_t *bindIp = L"";

	m_pTcpServer = HP_Create_TcpServer(m_pDataProcess.get());
	m_pTcpServer->SetWorkerThreadCount(1);
	if (!m_pTcpServer->Start(bindIp, 8888)){
		DWORD ret = GetLastError();
		assert(false);
	}
}

DNetServer::~DNetServer()
{
	m_pTcpServer->Stop();
	HP_Destroy_TcpServer(m_pTcpServer);
}

void DNetServer::sendPacket(HeadInfo headInfo, const char *data)
{
	auto &connId = m_pDataProcess->getConnid();
	if (connId.empty())
	{
		return;
	}

	m_pTcpServer->Send(connId[0], (BYTE *)&headInfo, sizeof(HeadInfo));
	m_pTcpServer->Send(connId[0],(BYTE *)data, headInfo.bodySize);
}
#endif